package com.ocm.pay.feign;

import com.ocm.pay.bo.PayOrderBO;
import lombok.AllArgsConstructor;
import com.ocm.core.log.exception.ServiceException;
import com.ocm.core.tool.api.R;
import com.ocm.pay.bo.RefundOrderBO;
import com.ocm.pay.service.IPayService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Author hqy
 * @Date 19/01/2022
 * @Description
 */
@RestController
@AllArgsConstructor
public class PayClient implements IPayClient{

	private final IPayService payService;

	@Override
	@PostMapping(API_PREFIX+"/deal")
	public R deal(@Valid @RequestBody PayOrderBO payOrderBO) {
		try {
			boolean deal = payService.deal(
				payOrderBO.getPayerId(), payOrderBO.getPayerName(), payOrderBO.getPayerType(),
				payOrderBO.getPayeeId(), payOrderBO.getPayeeName(), payOrderBO.getPayeeType(),
				payOrderBO.getAmount(), payOrderBO.getOrderId(), payOrderBO.getOrderDescribe(),
				payOrderBO.getCardId(), payOrderBO.getBankType(), payOrderBO.getBankCard(), payOrderBO.getCardType(),
				payOrderBO.getPayPassword(), payOrderBO.getRemark()
			);
			return  R.status(deal);
		}catch (ServiceException e){
			return  R.fail(e.getMessage());
		}
	}
	@PostMapping(API_PREFIX+"/receiving")
	@Override
	public R receiving(Long orderId) {
		try {
			payService.receiving(orderId);
			return R.success("收货成功");
		}catch (Exception e){
			return R.fail(e.getMessage());
		}
	}

	@PostMapping(API_PREFIX+"/refund")
	@Override
	public R<Void> refund(RefundOrderBO refundOrderBO) {

		payService.refund(refundOrderBO.getAmount(),refundOrderBO.getOrderId(),refundOrderBO.getRemark());
		return R.success("退款成功");


	}
}
